package com.htudata.hieyes.alarm.service;

import java.util.List;

import com.htudata.core.util.operation.CollectionsOperationUtils;
import com.htudata.hieyes.alarm.dao.AlarmStatisDao;
import com.htudata.hieyes.alarm.pojo.po.AlarmLevelPO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import javax.annotation.PostConstruct;

@Service
public class AlarmLevelService {

  public static final String DEFAULT_ALARM_LEVEL_COLOR = "#ffffff";
  
  private static int global_normal_level;

  @Autowired
  private AlarmStatisDao alarmStatisDao;
  
  @Value("${normal_level}")
  private int normal_level;

  @PostConstruct
  public void setGlobalNormalLevel() {
    global_normal_level = this.normal_level;
  }

  public static AlarmLevelPO getAlarmLevelInfo(List<AlarmLevelPO> alarmLevelList, int level) {
    if (!CollectionsOperationUtils.isValidCollection(alarmLevelList))
      return null; 
    for (AlarmLevelPO result : alarmLevelList) {
      if (result.getLevel() == level)
        return result; 
    } 
    return getAlarmLevelInfo(alarmLevelList, global_normal_level);
  }
  
  public List<AlarmLevelPO> getAlarmLevelList() {
    return this.alarmStatisDao.selectAlarmLevelList();
  }
}
